<!--
 * @Author: fengYM feng25321@163.com
 * @Date: 2023-10-07 09:39:50
 * @LastEditors: fengYM feng25321@163.com
 * @LastEditTime: 2023-10-17 14:53:05
 * @Description: 注册
-->
<template>
  <view class="con">
    <u-navbar title="" auto-back></u-navbar>
    <view class="title">注册账号</view>
    <view class="inputBox">
      <u-input v-model="formData.name" placeholder="请输入姓名" border="none"></u-input>
    </view>
    <view class="inputBox">
      <u-input v-model="formData.company" placeholder="请输入所属公司邀请码" border="none"></u-input>
    </view>
    <view class="inputBox">
      <u-input v-model="formData.cell" placeholder="请输入手机号" border="none"></u-input>
    </view>
    <view class="inputBox">
      <u-input v-model="formData.loginPwd" placeholder="请设置登录密码" border="none" :password="isPass">
        <template #suffix>
          <u-icon name="eye-off" color="#bfbfbf" size="28" v-if="isPass" @click="isPass = false"></u-icon>
          <u-icon name="eye" color="#bfbfbf" size="28" v-else @click="isPass = true"></u-icon>
        </template>
      </u-input>
    </view>
    <view class="radioBox">
      <u-radio-group>
        <u-radio :customStyle="{ marginTop: '12px' }" label="" name=""> </u-radio>
      </u-radio-group>
      <view class="text">登录即同意<text>《用户协议》</text>和<text>《隐私政策》</text></view>
    </view>
    <u-button type="primary" @click="submit">提交</u-button>
    <view class="register">已有账号？<text @click="goPage('/pages/login/login')">直接登录</text> </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { goPage } from "../../utils/commonFn";
import { getInfo, save } from "../../api/home";
const isPass = ref(true);
const formData = ref({
  cell: "",
  loginPwd: "",
  name: "",
  company: "",
});
const submit = async () => {
  if (!formData.value.cell) {
    uni.showToast({ icon: "none", title: "请输入手机号" });
    return;
  } else if (!formData.value.loginPwd) {
    uni.showToast({ icon: "none", title: "请输入密码" });
    return;
  } else if (!formData.value.name) {
    uni.showToast({ icon: "none", title: "请输入姓名" });
    return;
  } else if (!formData.value.company) {
    uni.showToast({ icon: "none", title: "请输入所属公司邀请码" });
    return;
  }
  const res2 = await getInfo({
    FormId: "BD_CommonContact",
    Data: {
      FieldKeys: "FName,FNumber,FCompany,FCompanyType,FMobile,FBizLocation,FBizLocNumber,F_TEZV_KEY",
      FilterString: [
        { Left: "(", FieldName: "FMobile", Compare: "=", Value: formData.value.cell, Right: ")", Logic: "AND" },
        { Left: "(", FieldName: "FCompany.FNumber", Compare: "=", Value: formData.value.company, Right: ")", Logic: "AND" },
      ],
      OrderString: "",
      TopRowCount: 0,
      StartRow: 0,
      Limit: 2000,
      SubSystemId: "",
      FormId: "BD_CommonContact",
    },
  });
  if (res2.length !== 0) {
    uni.showToast({
      title: "您已有账号，请直接登录",
      icon: "none",
    });
    return;
  }
  const res = await save({
    FormId: "BD_CommonContact",
    Data: {
      FormId: "BD_CommonContact",
      Model: {
        FName: formData.value.name,
        FCompanyType: "BD_Customer",
        FMobile: formData.value.cell,
        F_TEZV_KEY: formData.value.loginPwd,
        FCompany: {
          FNumber: formData.value.company,
        },
      },
    },
  });
  console.log(res);
  uni.showToast({
    title: "注册成功",
    icon: "success",
    complete: () => {
      uni.reLaunch({
        url: "/pages/login/login",
      });
    },
  });
};
</script>

<style lang="less" scoped>
.con {
  background: #fff;
  height: calc(100vh - 144rpx);
  padding: 144rpx 64rpx 0;
  /deep/ .u-navbar__content__right__text {
    color: #426efe;
  }
  .title {
    font-size: 56rpx;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 80rpx;
    margin-bottom: 50rpx;
  }
  .inputBox {
    padding: 20rpx 0;
    border-bottom: 1rpx solid #f9f9f9;
    .wjmm {
      font-size: 24rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 34rpx;
    }
  }
  .radioBox {
    display: flex;
    align-items: center;
    margin-top: 40rpx;
    margin-bottom: 120rpx;
    .u-radio-group[data-v-cbc8bf70] {
      flex: none;
    }
    .text {
      margin-top: 10rpx;
      font-size: 24rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #a6a9af;
      line-height: 34rpx;
      text {
        color: #426efe;
      }
    }
  }
  .register {
    text-align: center;
    font-size: 28rpx;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    line-height: 40rpx;
    margin-top: 40rpx;
    color: #333333;

    text {
      color: #426efe;
    }
  }
}
</style>
